﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using DotNet.Business;
using DotNet.Model;
using DotNet.Common;

public partial class Admin_adminProductAttribute : System.Web.UI.Page
{
    ProductAttributeBll proAttrBll = new ProductAttributeBll();
    productBll proBll = new productBll();
    AttributeBll atrBll = new AttributeBll();
    private static readonly object objSync = new object();
    public string input = "<input id=\"HiddenUrl\" type=\"hidden\" value=\"&CurrentIndex=1\" />";
    int pageSize = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["action"]!=null)
            {
                string action = Request.QueryString["action"].Trim();
                switch (action)
                {
                    case "delAll":
                        delelte();
                        break;
                    default:
                        break;
                }
            }
            BindProAttr();
        }
    }
    #region 删除
    public void delelte() 
    {
        int id = Convert.ToInt32(Request.QueryString["id"]);
        if (proAttrBll.Delete(id))
        {    
        
        }        
    }
    #endregion

    #region 绑定
    public void BindProAttr() 
    {
        if (Request.QueryString["CurrentIndex"]!=null)
        {
            _currentIndex = Convert.ToInt32(Request.QueryString["CurrentIndex"]);
        }
        if (Request.QueryString["AttributeID"]!=null)
        {
            _attributeid = Convert.ToInt32(Request.QueryString["AttributeID"]);
        }
        if (Request.QueryString["ProductID"]!=null)
        {
            _productid = Convert.ToInt32(Request.QueryString["ProductID"]);
        }
        DataTable dt = proAttrBll.pagingForProductAttribute(_currentIndex, pageSize, _attributeid, _productid);
        if (dt.Rows.Count==0&&_currentIndex>1)
        {
            --_currentIndex;
            dt = proAttrBll.pagingForProductAttribute(_currentIndex, pageSize, _attributeid, _productid);
        }
        input = "<input id='HiddenUrl' type='hidden' value='&CurrentIndex=" + _currentIndex + "' />";
        this.Repeater1.DataSource = dt;
        this.Repeater1.DataBind();
    }
    #endregion

    #region 状态维护
    public int _currentIndex = 1;
    public int _attributeid = 0;
    public int _productid = 0;
    #endregion

    #region 根据产品id获得产品名称---郑同飞
    public string getProductName(object productID)
    {
        product product=proBll.GetModel(Convert.ToInt32(productID));
        return product.Productmodel + product.productName; 
    }
    #endregion

    #region 根据属性id获得属性名称---郑同飞
    public string getAttributeName(object attributeID) 
    {
        Attribute atr = atrBll.GetModel(Convert.ToInt32(attributeID));
        return atr.attributeName;
    }
    #endregion

    #region 产品属性分页按钮
    public void PagingHtml()
    {
        string str = null;
        int count = 0;
        count = proAttrBll.getRecordCount(_attributeid, _productid);
        int pcount = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
        str = "页次：" + _currentIndex + "/" + pcount + "  每页" + pageSize + " 总收录数据" + count + "条";
        str += HtmlControls.pagIng(_currentIndex, pcount, "adminProductAttribute.aspx?AttributeID=" + _attributeid + "&ProductID="+_productid+ "&CurrentIndex", "pageaa", "pagecurrent");
        Response.Write(str);
    }
    #endregion
}
